﻿

using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using COM.Rights.Model;



namespace COM.Rights.BLL
{   
    public partial class TRoleTTTFunction 
    {

        public List<TRoleTTTFunctionInfo> GetFunctionByRole(string id)
        {
            List<TRoleTTTFunctionInfo> infos = new List<TRoleTTTFunctionInfo>();
            string filter = "TRole_GID=@TRole_GID";
            List<DBParameter> dps = new List<DBParameter>();
            dps.Add(new DBParameter("TRole_GID", id));          
            infos = GetList("", filter, "", dps);
            return infos;
        }

        public bool SaveFunctions(string roleGID, string functionIDS)
        {
            string ids = functionIDS.Trim(',');

            List<TRoleTTTFunctionInfo> infos = new List<TRoleTTTFunctionInfo>();

            foreach (string s in ids.Split(','))
            {
                if (!string.IsNullOrEmpty(s))
                {
                    TRoleTTTFunctionInfo info = new TRoleTTTFunctionInfo();
                    info.TRole_GID = roleGID;
                    info.TFunction_GID = s;
                    infos.Add(info);
                }
            }

            string filter = "TRole_GID=@TRole_GID";
            List<DBParameter> dps = new List<DBParameter>();
            dps.Add(new DBParameter("TRole_GID", roleGID));
            this.Delete(filter, dps);
            this.Add(infos, "");

            return true;
        }

        partial void OnBLLCreated() { ConfigName = "Rights"; }

	}
}